<?php
// 本类由系统自动生成，仅供测试用途
class MailAction extends Action {
    public function index(){
        header("Content-Type:text/html; charset=utf-8");
		$this->display();
        
    }
	public function sendmail(){
		$defultmail["getname"]=$_REQUEST["sendname"];
		if($_REQUEST["title"])
			$defultmail["title"]="Re:".$_REQUEST["title"];
		
		
		$this->assign("defultmail",$defultmail);
		$this->display();
	}
	public function send(){
      
		$Data = $_REQUEST["Data"];

		$Dao=D("Mail");
		$Data['sendname']=session('nickname');
		$Data['senddate']=date('Y-m-d');
		$count=0;
		$Getname=explode(',', $Data['getname']);
		foreach ($Getname as $id => $key) {
			$Data['getname']=$key;
			$Dao->add($Data);
			$count++;
		}
		if($count>0)		
			print_r("success!");
		else
			print_r("error!");
        
    }
	public function query(){
		$key=$_REQUEST["key"];
		$State=$_REQUEST["state"];
		
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];
	
		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];
		
		if(!empty($sortField)){
			if ($sortOrder != "desc") $sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		}else{
			$order = "mid desc";
		}
		
		$condition ['sendname'] = array ('like', '%' . $key . '%' );
		$condition ['getname'] = session('nickname');
		//$condition ['state'] = array ('like', '%' . $State . '%' ) ;
		
			if($State=='2')		
				$condition ['state'] = array('egt', '0');
			else	
				$condition ['state'] = $State;
		
		
		$Dao=D("Mail");
		
		$total = $Dao->where ( $condition )->count ();
		
		//dump($total);
		$list=$Dao->where($condition)->order ( $order )->limit ( $pageIndex * $pageSize. ',' . $pageSize )->select();
		
		//dump($list);
		$resultData = array("total"=>$total,"data"=>$list);

		$Data=json_encode($resultData);
		print_r($Data);
    
    }
	public function delete(){
		$mid=$_REQUEST["mid"];
		$condition['mid']=$mid;
		$Dao = M("Mail");
		if($Dao->where($condition)->delete())
			print_r("删除成功！");
	}
	public function read(){
		$mid=$_REQUEST["mid"];
		$condition['mid']=$mid;
		$data['state']="1";
		$Dao = M("Mail");
		if($Dao->where($condition)->save($data))
		
			print_r("更新成功！");
	}
	public function export(){
		
		header("Content-type:application/vnd.ms-excel; charset=utf-8");
		header("Content-Disposition:filename=test.xls");
		$columns=json_decode($_REQUEST["columns"]);
		mb_convert_encoding($columns,"gbk", "utf-8");
		print_r($columns);

	}
}